{% extends "base.html" %}

{% block title %}{{ page.title }} - Wiki{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-3">
        <h1>{{ page.title }}</h1>
        <div>
            <a href="{{ url_for('edit_wiki_page', page_title=page.title) }}" class="btn btn-primary">
                <i class="fas fa-edit"></i> 编辑
            </a>
            {% if current_user.id == page.author_id or current_user.is_admin %}
            <button class="btn btn-danger ms-2" data-bs-toggle="modal" data-bs-target="#deleteModal">
                <i class="fas fa-trash"></i> 删除
            </button>
            {% endif %}
        </div>

        <!-- 删除确认模态框 -->
        <div class="modal fade" id="deleteModal" tabindex="-1" aria-labelledby="deleteModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="deleteModalLabel">确认删除</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                    </div>
                    <div class="modal-body">
                        确定要删除"{{ page.title }}"页面吗？此操作无法撤销。
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                        <form action="{{ url_for('delete_wiki_page', page_title=page.title) }}" method="POST">
                            <button type="submit" class="btn btn-danger">确认删除</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="card mb-4">
        <div class="card-body">
            <div class="wiki-content">
                {{ page.content|markdown }}
            </div>
        </div>
        <div class="card-footer text-muted">
            <small>
                最后更新: {{ page.updated_at.strftime('%Y-%m-%d %H:%M') }} 
                | 创建者: {{ page.author.username }}
            </small>
        </div>
    </div>

    <div class="text-center">
        <a href="{{ url_for('wiki_index') }}" class="btn btn-outline-secondary">
            <i class="fas fa-arrow-left"></i> 返回Wiki首页
        </a>
    </div>
</div>
{% endblock %}
